package edu.zut.cs.network.Experiment5;

import org.apache.log4j.*;
import java.util.Scanner;

public class TwoDyadicArray1 {
    private static Logger logger = Logger.getLogger(TwoDyadicArray1.class);
    public static int printSum(int n){
        int sum = 0;
        int [][] arr = new int[n][n];
        logger.info("请输入"+n+"阶方阵的元素:");
        Scanner scanner = new Scanner(System.in);
        for(int i = 0; i < arr.length; i++) {
            String str1 = scanner.nextLine();
            String[] str2 = str1.split("[ ]+");
            for(int j = 0; j < arr[i].length;j++) {
                arr[i][j] = Integer.parseInt(str2[j]);
            }
        }
        for(int i = 0; i < arr.length; i++){
              sum = sum + arr[i][i];
        }
        return sum;
    }
    public static void main(String[] args) {
        logger.info("请输入n阶方阵的阶数：");
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        logger.info("您输入的矩阵是"+n+"行"+n+"列");
        int sum = TwoDyadicArray1.printSum(n);
        logger.info("该n阶方阵由左至右对角线上的所有元素的和为："+sum);
    }
}
